<template>
	<view>
		<view class="goods_list">
			<view @click="gotoGoodsDetail(goods)" v-for="(goods ,i) in goodsList" :key="i">
				<mygoods :goods='goods'></mygoods>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				queryObj: {
					cid: '',
					pageNum: 1,
					pageSize: 10,
					query: '',
					isLoading: false
				},
				goodsList: [{
						goods_pic: 'https://img2.baidu.com/it/u=612844894,2239973497&fm=253&fmt=auto&app=138&f=JPEG?w=334&h=500',
						good_name: 'sfa',
						goods_price: '23432',
						goods_id:34324
					},
					{
						goods_pic: 'https://img2.baidu.com/it/u=612844894,2239973497&fm=253&fmt=auto&app=138&f=JPEG?w=334&h=500',
						good_name: 'sfa',
						goods_price: '23432',
						goods_id:34232
					},
					{
						goods_pic: 'https://img2.baidu.com/it/u=612844894,2239973497&fm=253&fmt=auto&app=138&f=JPEG?w=334&h=500',
						good_name: 'sfa',
						goods_price: '23432',
						goods_id:56544
					},
					{
						goods_pic: 'https://img2.baidu.com/it/u=612844894,2239973497&fm=253&fmt=auto&app=138&f=JPEG?w=334&h=500',
						good_name: 'sfa',
						goods_price: '23432',
						goods_id:321131
					},
					{
						goods_pic: 'https://img2.baidu.com/it/u=612844894,2239973497&fm=253&fmt=auto&app=138&f=JPEG?w=334&h=500',
						good_name: 'sfa',
						goods_price: '23432',
						goods_id:12098
					},
					{
						goods_pic: 'https://img2.baidu.com/it/u=612844894,2239973497&fm=253&fmt=auto&app=138&f=JPEG?w=334&h=500',
						good_name: 'sfa',
						goods_price: '23432',
						goods_id:12555
					},
					{
						goods_pic: 'https://img2.baidu.com/it/u=612844894,2239973497&fm=253&fmt=auto&app=138&f=JPEG?w=334&h=500',
						good_name: 'sfa',
						goods_price: '23432',
						goods_id:12484
					},
				],
				total: 0,
			};
		},
		onLoad(option) {
			this.queryObj.query = option.query || '',
				this.queryObj.cid = Option.cid || ''
			this.getGoodsList()
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.total=0
			this.queryObj.pageNum=1
			this.isLoading=false
			this.getGoodsList(()=>uni.stopPullDownRefresh())
		},
		// 下拉加载
		onReachBottom() {
			// 数据加载完毕的处理
			if (this.queryObj.pageSize * this.queryObj.pageNum >= this.total)
				return uni.$showMsg('数据加载完毕')
			if (this.isLoading) return
			this.queryObj.pageNum += 1;
			this.getGoodsList()
		},
		methods: {
			gotoGoodsDetail(item){
				uni.navigateTo({
					url:"/subpkg/goods_detail/goods_detail?goods_id="+item.goods_id
				})
			},
			// 获取商品列表
			async getGoodsList(e) {
				// d打开节流阀
				this.isLoading = true
				const {
					data: res
				} = uni.$http.get('/api/adf', this.queryObj)
				this.isLoading = false
				e && e()//存在，才会调用回调函数
				if (res.mate.status !== 200) return uni.$showMsg()
				// this.goodsList = res.message
				this.goodsList = [...this.goodsList, ...res.message]
				this.total = res.message.total
			},
		}
	}
</script>

<style lang="scss">
	.goods_list {
		padding: 5px;
	}
</style>